<template>
  <section>
      <div class="filter-container">
            <el-button size="mini" class="ml10" type="primary" icon="el-icon-refresh" @click="handleSync">同步选品库</el-button>
        </div>
      <el-table :data="list"
                style="width: 100%">
            
            <el-table-column align="center" label="选品库名称">
                <template slot-scope="scope">
                    <span>{{scope.row.name}}</span>
                </template>
            </el-table-column>
            <el-table-column align="center" label="创建时间">
                <template slot-scope="scope">
                    <span>{{scope.row.createdAt}}</span>
                </template>
            </el-table-column>
            <el-table-column align="center" label="商品数量">
                <template slot-scope="scope">
                    <el-button type="text" @click="handleDetail(scope.row)">{{scope.row.feedCount}}</el-button>
                </template>
            </el-table-column>
            <el-table-column
                    fixed="right"
                    label="操作"
                    width="100">
                <template slot-scope="scope">
                    <el-button type="text" @click="handleGoods(scope.row)">同步商品</el-button>
                </template>
            </el-table-column>
        </el-table>

        
  </section>
</template>

<script>
    import {
        alibaba_group,
        alibaba_group_sync,
        alibaba_goods_sync
    } from '../../api/alibaba';
export default {
    components: {
    },
  data() {
    return {
        list: null,
        listLoading: true,
    }
  },
  mounted() {
  },
        created() {
            this.getList();
        },

  methods: {
    getList() {
        this.listLoading = true;
        alibaba_group().then(response => {
            this.list = response.data;
            this.listLoading = false;
        })
    },
    handleSync() {
        this.$confirm('确定同步选品库?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
        })
            .then(() => {
                alibaba_group_sync()
                    .then(() => {
                        this.$message.success("选品库已同步");
                        this.getList();
                    });
            }).catch(()=>{});
    },
    handleGoods(item) {
        this.$confirm('确定同步商品?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
        })
            .then(() => {
                alibaba_goods_sync(item.id)
                    .then(() => {
                        this.$message.success("商品已同步");
                    });
            }).catch(()=>{});
    },
    handleDetail(item) {
        this.$router.push("/alibaba_goods?id=" + item.id) 
    }
  }
};
</script>
